package cn.richard.demo.ruleengine.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;

import org.jeasy.rules.api.Rule;
import org.jeasy.rules.api.Rules;

public class MyRulesUtil {
	public static int countRules(Rules rules) {
		int count = 0;
		if(Objects.nonNull(rules) && !rules.isEmpty()) {
			Iterator<Rule> iterator = rules.iterator();
			while(iterator.hasNext()) {
				Rule rule = iterator.next();
				//System.out.println(rule);
				count+=1;
			}
		}
		return count;
	}
	
	public static Map<String, Rule> rulesMap(Rules rules) {
		Map<String, Rule> map = new HashMap<>();
		if(Objects.nonNull(rules) && !rules.isEmpty()) {
			rules.forEach(o -> map.put(o.getName(), o));
		}
		return map;
	}
	
}
